<template>
	<view class="content_box" style="background: #fff;">
		<view class="u-flex u-col-center wrapper-box" >
			<view class="scroll-box" style="background-color: #F6F6F6;padding-top: 20rpx;">
				<scroll-view class="left u-flex-col u-col-center" enable-flex enable-back-to-top scroll-y>
					<view class="type-list u-ellipsis-1" :class="[{ 'list-active': listId == index }]"
						v-for="(item, index) in categoryData" :key="index" @tap="onType(index)">
						<view class="line"></view>
						{{ item.name }}
					</view>
					<view class="hack-tabbar"></view>
				</scroll-view>
			</view>
			<view style="height: 100%;width:80%;">
				<scroll-view scroll-y class="scroll-box" enable-flex enable-back-to-top scroll-with-animation>
					<view class="right" v-if="categoryData.length">
						<image class="type-img" 
						v-if="categoryData[listId].icon"
						:src="categoryData[listId].icon"
						mode="aspectFill"></image>
						<view class="item-list" >
							<view class="item-box">
								<view class="goods-item"
									v-for="(mlist, index2) in categoryData[listId].children" :key="index2"
									>
									<view class="item-titles">
									  {{mlist.name}}
									</view>
									<view style="display: flex;flex-wrap: wrap;">
									  <view class="three-box"
											v-for="(items,indexs) in mlist.children"
											@tap="jump('/pages/tuandui/product', { id: items.id })"
									  >
										<image class="item-img" lazy-load :src="items.meta.icon" mode="aspectFill"></image>
										<view class="item-title u-ellipsis-1 ">{{ items.name }}</view>
									  </view>
									</view>
								</view>
							</view>
					  	</view>
						<!-- 缺省页 -->
						<ljshop-empty v-show="!categoryData[listId].children.length"
							:image="$IMG_URL + '/imgs/empty/empty_cate.png'" tipText="暂无该商品，还有更多好货等着你噢~">
						</ljshop-empty>
						<view class="hack-tabbar"></view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	export default {
		data() {
			return {
				listId: 0,
				categoryData: {}
			};
		},
		computed: {},
		props: {
			categoryStyleId: {
				type: Number,
				default: 0
			}
		},
		async created() {
			await this.getCategory();
		},
		methods: {
			filterImg(e){
				console.log(e);
			},
			getCategory() {
				uni.showLoading({})
				this.$http('category.info').then(res => {
					if (res) {
						uni.hideLoading()
						let orgList = res.data
						// for (let i = 0; i < orgList.length; i++) {
						// 	if(orgList[i].hasContent){
						// 		let list = [];
						// 		for (let j = 0; j < orgList[i].children.length; j++) {
						// 			for (let k = 0; k < orgList[i].children[j].children.length; k++) {
						// 				if(orgList[i].children[j].children[k].hasContent){
						// 					list.push(orgList[i].children[j].children[k])
						// 				}
						// 			}
						// 		}
						// 		orgList[i].children = list;
						// 	}
						// }
						this.categoryData = orgList;
					}
				});
			},
			onType(id) {
				this.listId = id;
			},
			// 路由跳转
			jump(path, parmas) {
				this.$Router.push({
					path: path,
					query: parmas
				});
			}
		},
	};
</script>

<style lang="scss">
	.hack-tabbar {
		height: calc(100rpx + env(safe-area-inset-bottom) / 2);
		width: 100%;
	}

	.content_box {
		margin-top: 1upx;
		display: flex;
		flex-direction: column;
		overflow: hidden;
		height: 100%;
	}

	.wrapper-box {
		flex: 1;
		margin-top: 1rpx;
		height: 100%;
	}

	.scroll-box {
		height: 100%;
		flex: 1;
		background: #fff;
	}

	.left {
		width: 200rpx;
		height: 100%;
		flex: 1;

		.list-active {
      color: #ff5733 !important;
      font-size: 30rpx !important;
      font-weight: 600 !important;
		}

		.line-active {
			background: #F3A326;
		}

		.type-list {
			text-align: center;
			height: 110rpx;
			position: relative;
			width: 100%;
			//padding-left: 16rpx;
			line-height: 84rpx;
			font-size: 28upx;
			font-weight: 400;
			color: rgba(102, 102, 102, 1);

			.line {
				width: 10upx;
				height: 100%;
				position: absolute;
				left: 0;
			}
		}
	}

	.right {
		padding: 0 10rpx;
		flex: 1;
		height: 100%;

		.type-img {
			width: 505rpx;
			height: 150rpx;
			background: #ccc;
			border-radius: 10rpx;
			margin-top: 30rpx;
		}

		.item-list {
			.type-box {
				height: 84rpx;

				.type-title {
					font-size: 28rpx;
					font-weight: bold;
				}

				.more {
					font-size: 26rpx;
					color: #999;
				}
			}

			.item-box {
				flex-wrap: wrap;

				.goods-item {
					margin-right: 20rpx;
					margin-bottom: 20rpx;
          display: flex;
          flex-direction: column;

					&:nth-child(3n) {
						margin-right: 0;
					}

					.item-img {
						width: 100rpx;
						height: 100rpx;
						background: #f5f5f5;
						border-radius: 6rpx;
					}

					.item-title {
						font-size: 24rpx;
						line-height: 24rpx;
						margin-top: 10rpx;
						padding-top: 10rpx;
						width: 150rpx;
						text-align: center;
					}
				}
			}
		}
	}
  .three-box{
    margin-bottom: 45rpx;
    margin-left: 20rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .item-titles{
    margin-top: 25rpx;
    margin-bottom: 25rpx;
    font-weight: bold;
	color: #000;
    padding-left: 20rpx;
  }
</style>
